<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>login</title>
    <!-- 新 Bootstrap4 核心 CSS 文件 -->
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/css/bootstrap.min.css">

    <!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
    <script src="https://cdn.staticfile.org/jquery/3.2.1/jquery.min.js"></script>

    <!-- popper.min.js 用于弹窗、提示、下拉菜单 -->
    <script src="https://cdn.staticfile.org/popper.js/1.12.5/umd/popper.min.js"></script>

    <!-- 最新的 Bootstrap4 核心 JavaScript 文件 -->
    <script src="https://cdn.staticfile.org/twitter-bootstrap/4.1.0/js/bootstrap.min.js"></script>
</head>
<body>
<input id="username" type="text" placeholder="请输入用户名"><br>
<input id="password" type="password" placeholder="请输入密码"><br>
<button onclick="find()" >登录</button><button onclick="add()" >注册</button>
<!--<form action="/login" method="get">-->
<!--    <input name="username">-->
<!--    <input name="password">-->
<!--    <button type="submit"> 提交</button>-->
<!--</form>-->
</body>

<script type="text/javascript">
    function find() {
        var username = $("#username").val()
        var password = $("#password").val()
        if(username == "" || username.length == 0){
            alert("请输入用户名")
            return false
        }
        if(password == "" || password.length == 0){
            alert("请输入密码")
            return false
        }
        $.ajax({
            type: "get",
            url: "http://localhost:8080/login",
            data: {"username": username, "password": password},
            success: function (data) {
                if (data != null) {
                    alert("登录成功")
                    window.location.href = "http://localhost:8080/user/select"
                }

                 else{
                    alert("登录失败")
                    return false
                 }

            }
        });

    }
    function add() {
        var username = $("#username").val()
        var password = $("#password").val()

        if(username == "" || username.length == 0){
            alert("请输入用户名")
            return false
        }
        if(password == "" || password.length == 0){
            alert("请输入密码")
            return false
        }
        if(role == "" || role.length == 0){
            alert("请输入密码")
            return false
        }
        $.ajax({
            type: "get",
            url: "http://localhost:8080/user/insert",
            data: {"username": username, "password": password},
            success: function (data) {
                if (data == 1) {
                    alert("注册成功")
                    window.location.href = "index.html"
                }
                else{
                    alert("注册失败")
                    return false
                }
            }
        });

    }
    </script>

</body>
</html>